﻿<%@ WebHandler Language="C#" Class="count" %>

using System;
using System.Web;
using YuuzleComic.DBUtility;
using System.Data.SqlClient;
using System.Data;
using System.Globalization;

public class count : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        if (context.Request["bookId"] != null)
        {
            SqlParameter[] parameters = new SqlParameter[]{ 
                new SqlParameter("@id",context.Request["bookId"])
            };
            string sql = "update comics set hits=hits+1,";
            sql += "hits_m=case when DATEPART(MONTH,hits_m_d)=DATEPART(MONTH,getdate()) then hits_m+1 else 1 end,hits_m_d=getdate(),";
            sql += "hits_w=case when hits_w_d=DATEPART(WEEK,getdate()) then hits_w+1 else 1 end,hits_w_d=DATEPART(WEEK,getdate()),";
            sql += "hits_d=case when DATEPART(DAY,hits_m_d)=DATEPART(DAY,getdate()) then hits_d+1 else 1 end ";
            sql += "where id=@id";
            DbHelperSQL.ExecuteSql(sql, parameters);
        }
        if (context.Request["chapterId"] != null)
	    {
            System.Data.SqlClient.SqlParameter[] parameters = new System.Data.SqlClient.SqlParameter[]{ 
                new System.Data.SqlClient.SqlParameter("@id",context.Request["chapterId"])
            };
            DbHelperSQL.ExecuteSql("update zj set hits=case when hits is null then 1 else hits+1 end where id=@id", parameters);
	    }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}